package com.mw.wmimobile.gui.fragments;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.mw.wmimobile.datastorage.StaffDto;
import com.mw.wmimobile.gui.activities.ClassesClassActivity;
import com.mw.wmimobile.gui.activities.StaffPersonActivity;
import com.wm.wmimobile.R;

public class StaffAdapter extends ArrayAdapter<StaffDto> {

	private Context context;
	private List<StaffDto> staffDtoList;

	private TextView nameTextView;
	private TextView fieldTextView;
	private TextView officeTextView;
	
	private int[] listItemBackground = new int[] {
			R.drawable.staff_list_backgroung_1_transp,
			R.drawable.staff_list_backgroung_2_transp 
			};
	
	public StaffAdapter(Context context, List<StaffDto> list) {
		super(context, R.layout.staff_adapter_listitem, list);
		this.context = context;
		this.staffDtoList = list;
	}
		
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
		View rowView = inflater.inflate(
				R.layout.staff_adapter_listitem, parent, false);
		
		nameTextView = (TextView)
				rowView.findViewById(R.id.FragmentStaffNameTextItem);
		fieldTextView = (TextView)
				rowView.findViewById(R.id.FragmentStaffFieldTextItem);
//		officeTextView = (TextView) 
//				rowView.findViewById(R.id.FragmentStaffOfficeTextItem);
		
		final StaffDto staff = staffDtoList.get(position);
		//nameStr = add.getName() == null ? "null" : add.getName();
		
		Spanned spanned;
		
		String nameString = staff.getName();
		spanned = android.text.Html.fromHtml("<b>" + nameString + "</b>");
		nameTextView.setText(spanned);
		
//		String officeString = staff.getDegree();
//		spanned = android.text.Html.fromHtml(officeString);
//		officeTextView.setText(spanned);
		
		
		String room = staff.getRoom();
		spanned = android.text.Html.fromHtml("<b>" + room + "</b>");
		fieldTextView.setText(spanned);
		
		int listItemBackgroundPosition = position % listItemBackground.length;
        rowView.setBackgroundResource(listItemBackground[listItemBackgroundPosition]);
		
//        rowView.setOnClickListener(new OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				Intent intent = new Intent(context,
//						StaffPersonActivity.class);
//				intent.putExtra("codeIntent", staff.getName());
//				context.startActivity(intent);
//			}
//		});
        
		return rowView;
	}

}
